package  
{
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.graphics.Text;
	import net.flashpunk.World;
	import net.flashpunk.utils.Input;
	import net.flashpunk.utils.Key;
	import net.flashpunk.tweens.misc.VarTween;
	import net.flashpunk.utils.Ease;
	import net.flashpunk.Sfx;

	
	public class MainMenuWorld extends World 
	{
		
		[Embed(source = "sfx/Rags To Riches - Tony Bennett.mp3")]private const TITLE_MP3:Class;
		private var titleSfx:Sfx;
		
		[Embed(source = "img/cover.png")]	private const IMG_BACK:Class;
		private var imgBack:Image;
		
		private var helpTween:VarTween;
		private var helpText:Text;
		
		private var title1Tween:VarTween;
		private var title1Text:Text;
		
		private var estado:String;
		
		private var time:Number;
		private var counter:int = 0;
		
		public function MainMenuWorld() 
		{
			imgBack = new Image(IMG_BACK);
			imgBack.x = 200;
			imgBack.y = 0;
			addGraphic(imgBack);
			
			estado="ALPHA0"
			time = 0.0;
			
			helpText = new Text("Clic para comenzar.");
			helpText.x = 550;
			helpText.y = 550;
			helpText.alpha = 0;
			helpTween=new VarTween()
						
			
			title1Text = new Text("ONE BUTTON GOODFELLA");
			title1Text.scale = 2;
			title1Text.x = 900;
			title1Text.y = 450;
			title1Text.color = 0x831405;
			title1Tween = new VarTween();
			
			this.addGraphic(helpText);
			this.addGraphic(title1Text);
						
			this.addTween(helpTween);
			this.addTween(title1Tween);
			
			titleSfx = new Sfx(TITLE_MP3);
			titleSfx.loop();
			
		}
		
		override public function begin():void
		{
			title1Tween.tween(title1Text, "x", -400, 0.5);
		}
			
		
		override public function update():void
		{
			
			if (Input.mouseReleased)
			{
				playTheGame();
			}
			
			if (estado == "ALPHA0")
			{
				helpTween.tween(helpText, "alpha", 1, 1);
				estado = "WAIT";
				
			}
			else if (estado =="ALPHA1")
			{
				helpTween.tween(helpText, "alpha", 0,1);
				estado = "WAIT";
			}
			
			
			if (helpTween.percent == 1  && estado == "WAIT")
			{
					if (helpText.alpha == 1)
						estado = "ALPHA1"
					else
						estado = "ALPHA0";
			}
			
			time += FP.elapsed;
			if ( time>0.5 && time <5)
			{	
				if (counter < 2)
				{
					title1Text.x = 900;
					title1Tween.tween(title1Text, "x", -400, 0.5);
					counter += 1
					time = 0.0;
				}
				else	
				{	time = 5;
					title1Text.x = 225;
				}
			}
			super.update();
		}
		
		private function playTheGame():void 
		{
			
			FP.world = new IntermediaScene("Todo empezo cuando lleve a mi chica a cenar",new FirstScene());
			titleSfx.stop();
			removeAll();
		}
		
		
		
	}

}